//
//  OrderDetailTableViewCell.m
//  SsehMaster
//
//  Created by 杨阳 on 2018/8/4.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "OrderDetailTableViewCell.h"
#import "OrderInforModel.h"
#import "NSString+BRSize.h"

@interface OrderDetailTableViewCell()


@property (weak, nonatomic) IBOutlet UIView *tipBgView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *itemHeightLayouConstraint;
@property (weak, nonatomic) IBOutlet UILabel *itemLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *itemWidth;

@property (weak, nonatomic) IBOutlet UILabel *itemLabel2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *item2Width;

@property (weak, nonatomic) IBOutlet UILabel *itemLabel3;

@property (weak, nonatomic) IBOutlet UILabel *troubleDesLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UIButton *rightButton;
@property (weak, nonatomic) IBOutlet UIButton *midButton;
@property (weak, nonatomic) IBOutlet UIButton *leftButton;
@property (nonatomic,strong) NSIndexPath * index;

@property (nonatomic,strong) OrderDetail * orderModel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *midButtonWidth;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightButtonWidth;

@end

@implementation OrderDetailTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.itemLabel.layer.borderColor = [UIColor appColor].CGColor;
    self.itemLabel.layer.borderWidth = 1.0f;
    self.itemLabel.layer.cornerRadius = 5;
    
    self.itemLabel2.layer.borderColor = [UIColor appColor].CGColor;
    self.itemLabel2.layer.borderWidth = 1.0f;
    self.itemLabel2.layer.cornerRadius = 5;
    self.itemLabel2.hidden = YES;
    
    self.itemLabel3.layer.borderColor = [UIColor appColor].CGColor;
    self.itemLabel3.layer.borderWidth = 1.0f;
    self.itemLabel3.layer.cornerRadius = 5;
    self.itemLabel3.hidden = YES;
    
    self.rightButton.layer.borderColor = [UIColor roseRed].CGColor;
    self.rightButton.layer.borderWidth = 1.0f;
    self.rightButton.layer.cornerRadius = 5;
    
    self.midButton.layer.borderColor = [UIColor roseRed].CGColor;
    self.midButton.layer.borderWidth = 1.0f;
    self.midButton.layer.cornerRadius = 5;
    
    self.leftButton.layer.borderColor = RGBColor(185, 185, 185).CGColor;
    self.leftButton.layer.borderWidth = 1.0f;
    self.leftButton.layer.cornerRadius = 5;
    
}

- (IBAction)rigntOnClick:(id)sender {
    
    if (_rightButtonClick) {
        _rightButtonClick(self.index,self.orderModel);
    }
    
}

- (IBAction)midOnClick:(id)sender {
    
    if (_midButtonClick) {
        _midButtonClick(self.index);
    }
    
}

- (IBAction)leftOnClick:(id)sender {
    
    if (_leftButtonClick) {
        _leftButtonClick(self.index);
    }
    
}


-(void)configData:(OrderDetail *)model andSsehOrderType:(SsehOrderType)type andIndexPath:(NSIndexPath *)index{
    
    self.index = index;
    self.orderModel = model;
    self.troubleDesLabel.text = [NSString emptyStr:model.maintail_remark];
    NSString * dataStr = [self serviceTime:model.service_start_time andEndTime:model.service_end_time];
    self.dateLabel.text = dataStr;
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@",model.maintailOrderAddressBean.address_city,model.maintailOrderAddressBean.address_country,model.maintailOrderAddressBean.address_detailed];
    
    if ([model.order_state isEqualToString:@"0"]) {//已关闭
        self.midButtonWidth.constant = 0.0f;
        self.rightButtonWidth.constant = 0.0f;
        self.leftButton.userInteractionEnabled = NO;
        self.midButton.userInteractionEnabled = NO;
        self.rightButton.userInteractionEnabled = NO;
        [self.leftButton setTitle:@"已关闭" forState:UIControlStateNormal];
    }else if ([model.order_state isEqualToString:@"2"]){//待上门
        self.midButtonWidth.constant = 75.0f;
        self.rightButtonWidth.constant = 75.0f;
        
        self.leftButton.userInteractionEnabled = YES;
        self.midButton.userInteractionEnabled = YES;
        self.rightButton.userInteractionEnabled = YES;
        [self.leftButton setTitle:@"取消订单" forState:UIControlStateNormal];
        [self.rightButton setTitle:@"确认服务" forState:UIControlStateNormal];
    }else if ([model.order_state isEqualToString:@"3"]){//等待确认服务
        self.midButtonWidth.constant = 0.0f;
        self.rightButtonWidth.constant = 75.0f;
        self.leftButton.userInteractionEnabled = YES;
        self.midButton.userInteractionEnabled = NO;
        self.rightButton.userInteractionEnabled = NO;
        [self.leftButton setTitle:@"取消订单" forState:UIControlStateNormal];
        [self.rightButton setTitle:@"修改" forState:UIControlStateNormal];
    }else if ([model.order_state isEqualToString:@"5"]||
              [model.order_state isEqualToString:@"4"]){//已付款
        self.midButtonWidth.constant = 0.0f;
        self.rightButtonWidth.constant = 0.0f;
        self.leftButton.userInteractionEnabled = NO;
        self.midButton.userInteractionEnabled = NO;
        self.rightButton.userInteractionEnabled = NO;
        [self.leftButton setTitle:@"已完成" forState:UIControlStateNormal];
    }else{
        self.leftButton.userInteractionEnabled = YES;
        self.midButton.userInteractionEnabled = YES;
        self.rightButton.userInteractionEnabled = YES;
    }
    
    NSArray * tipsArr = [model.parts_names componentsSeparatedByString:@","];
    
    switch (tipsArr.count) {
        case 1:
            self.itemLabel.hidden = NO;
            self.itemLabel2.hidden = YES;
            self.itemLabel3.hidden = YES;
            break;
        case 2:
            self.itemLabel.hidden = NO;
            self.itemLabel2.hidden = NO;
            self.itemLabel3.hidden = YES;
            break;
        case 3:
            self.itemLabel.hidden = NO;
            self.itemLabel2.hidden = NO;
            self.itemLabel3.hidden = NO;
            break;
        default:
            self.itemLabel.hidden = YES;
            self.itemLabel2.hidden = YES;
            self.itemLabel3.hidden = YES;
            break;
    }
    
    for (NSInteger i = 0; i < tipsArr.count; i++) {
        NSString * tipStr = tipsArr[i];
        switch (i) {
            case 0:
                self.itemLabel.text = [NSString stringWithFormat:@"   %@   ",tipStr];
                self.itemWidth.constant = [self.itemLabel.text widthWithFont:[UIFont systemFontOfSize:12] constrainedToHeight:20];
                break;
            case 1:
                self.itemLabel2.text = [NSString stringWithFormat:@"   %@   ",tipStr];
                self.item2Width.constant = [self.itemLabel2.text widthWithFont:[UIFont systemFontOfSize:12] constrainedToHeight:20];
                break;
            case 2:
                self.itemLabel3.text = [NSString stringWithFormat:@"   %@   ",tipStr];
                break;
            default:
                break;
        }
    }
    
    
}

-(NSString *)serviceTime:(NSString *)startTime andEndTime:(NSString *)endTime{
    
    
    NSString * dateStr1 = [NSString stringWithFormat:@"%@-%@-%@",[NSString setNowTimeShow:0 andTimeStr:startTime],[NSString setNowTimeShow:1 andTimeStr:startTime],[NSString setNowTimeShow:2 andTimeStr:startTime]];
    
    NSString * dateStr3 = [NSString stringWithFormat:@"%@:%@-%@:%@",[NSString setNowTimeShow:3 andTimeStr:startTime],[NSString setNowTimeShow:4 andTimeStr:startTime],[NSString setNowTimeShow:3 andTimeStr:endTime],[NSString setNowTimeShow:4 andTimeStr:endTime]];
    NSString * dateStr = [NSString stringWithFormat:@"%@    %@",dateStr1,dateStr3];
    
    if (kStringIsEmpty(dateStr)) {
        return @"";
    }
    
    return dateStr;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end






